package C;

import java.util.Arrays;
import java.util.Scanner;

public class C43 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums = Arrays.stream(sc.nextLine().split(",")).mapToInt(Integer::parseInt).toArray();
        int n = sc.nextInt();
        Arrays.sort(nums);
        int count = 0,sum = 0;
        for (int i=0;i<nums.length;i++) {
            if (sum + nums[i] <= n) {
                sum+=nums[i];
                count++;
            } else {
                break;
            }
        }
        System.out.println(count);

    }
}
